<template>
  <div class="toolbar">
    <el-avatar
      src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
      class="mr-1"
    />
    <el-dropdown @command="handleCommand">
      <span class="el-dropdown-link">
        {{ user.name }}
        <el-icon class="el-icon--right">
          <arrow-down />
        </el-icon>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="Personal " icon="user" @click="userCenter">
            个人中心
          </el-dropdown-item>
          <el-dropdown-item command="Clear" icon="Delete" @click="clearStore()">
            清除缓存
          </el-dropdown-item>
          <el-dropdown-item
            command="Logout"
            icon="SwitchButton"
            @click="logout"
          >
            注销
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts" setup>
import router from '@/route';
import { store } from '@/store';

const user = store.user.state;
/**
 * 下拉菜单点击事件回调
 * @param {string | number | object} command ss
 */
function handleCommand(command: string) {
  switch (command) {
    case 'Logout':
      break;

    default:
      break;
  }
}
/** 个人中心 */
function userCenter() {
  router.push('/accountmanagement/usercenter');
}
/**
 * 注销登录
 */
function logout() {
  sessionStorage.clear();
  router.push('/login');
}
function clearStore() {
  localStorage.clear();
  store.user.clean();
}
</script>

<style lang="scss" scoped>
.toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}
</style>
